/*
 *  $Id: OpenCard.cs 1218 2010-11-28 14:03:06Z thenn.erannor $
 *	This file is a part of Ragima CCG.
 *	(C) 2008-2010 Ragima development group.
 *
 *	Licensed under the terms of the GNU GPL License version 2.
 *
 */

using Nereal.Extensions;
using Nereal.Serialization;

namespace Ragima.Events {
    [TypeId("opencard"), ConstructorParameters("_player", "_cardNumber")]
    public class OpenCard : GameEvent {
        [Serialize, XmlName("player"), Reference(true, typeof(bool), Ragima.Serialization.Resolvers.GamePlayer)]
        private readonly Player _player;
        [Serialize, XmlName("card"), DefaultValue(-1)]
        private readonly int _cardNumber;

        public OpenCard(Player player, int cardNumber) {
            _player = player;
            _cardNumber = cardNumber;
        }
        public OpenCard(Player player, HandCard card) : this(player, player.Hands.IndexOf(card)) {
        }

        protected override void ExecuteInner(Game scene) {
            var card = _player.Hands.GetOrDefault(_cardNumber);
            if (card != null && !card.Opened)
                card.Opened = true;
        }
    }
}
